home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 139_01.zip / KAREL1.C < prev    next >
Text File  |  1993-06-03  |  17KB  |  671 lines

  1. /*
  2. TITLE:        Karel The Robot;
  3. VERSION:    1.0;
  4. DATE:        09/27/1984;
  5. DESCRIPTION:
  6.     "Source code for Karel world builder.";
  7. KEYWORDS:    Robot, world, builder;
  8. SYSTEM:        CP/M 2+;
  9. FILENAME:    KAREL1.C;
  10. AUTHORS:    Linda Rising;
  11. COMPILERS:    BDS C;
  12. REFERENCES:
  13.     AUTHOR: Richard E. Pattis;
  14.     TITLE: "KAREL the Robot: A Gentle Introduction
  15.         to the Art of Programming";
  16.     CITATION: "";
  17. ENDREF
  18. */
  19.  
  20. #include <bdscio.h>             /* standard header */
  21.  
  22. #define CURPOS  "\033="        /* cursor control ESC = */
  23. #define X_POS       32        /* cursor control for x */
  24. #define Y_POS       32        /* cursor control for y */
  25. #define FILE  struct _buf    /* label for file header */
  26.  
  27. char world[23][75];             /* array for Karel's world */
  28. int bag;                /* Karel's beeper bag */
  29. int kst;            /* Karel's street */
  30. int kav;            /* Karel's avenue */
  31. char kdir;            /* Karel's direction */
  32. int last;            /* next loc in sym table */
  33.  
  34. main(argc,argv)
  35. int argc;            /* number of arguments for main */
  36. char **argv;            /* arg vector */
  37. {
  38.       char ans;
  39.       char ibuf2[BUFSIZ];
  40.  
  41.       if (argc < 3)
  42.          printf("MISSING FILENAME(S)\n");
  43.       else {
  44.          if (fopen(argv[2],ibuf2) != ERROR) {
  45.             readworld(ibuf2);
  46.             printworld();
  47.          } else { 
  48.               initworld(); 
  49.                   printworld();
  50.            }
  51.          fclose(ibuf2);
  52.          set_curs(23,0,0,"CHANGE KAREL'S LOCATION? (Y/N)");
  53.          if ((ans = toupper(getchr())) != 'N')
  54.             kareloc();
  55.          set_curs(23,0,75,"CHANGE BEEPERS IN WORLD? (Y/N)");
  56.          if ((ans = toupper(getchr())) != 'N')
  57.              beeploc();
  58.          set_curs(23,0,75,"CHANGE BEEPERS IN BAG? (Y/N)");
  59.          if ((ans = toupper(getchr())) != 'N')
  60.         bagloc();
  61.          set_curs(23,0,75,"CHANGE WALL LOCATIONS? (Y/N)");
  62.          if ((ans = toupper(getchr())) != 'N')
  63.             wallsloc();
  64.          alterations();
  65.          set_curs(23,0,75,"EXECUTE PROGRAM? (Y/N)");
  66.          if ((ans = toupper(getchr())) != 'Y') {
  67.         set_curs(23,0,75,"EXIT KAREL? (Y/N)");
  68.         if ((ans = toupper(getchr())) != 'N')
  69.            exit();
  70.          }
  71.          saveworld(argv,ibuf2);
  72.          createpgm(argv);      
  73.       }
  74. }
  75.  
  76.  
  77. initworld()   /* initialize "empty world" */
  78. {
  79.           int i,j;
  80.           char c;
  81.  
  82.       kst = 21;                        /* init Karel's st */
  83.       kav = 4;                /* init Karel's ave */
  84.       kdir = '0';                /* init Karel's dir */
  85.  
  86.           for (i = 0; i < 23; i++)
  87.             for (j = 0; j < 75; j++)         /* blank out array */
  88.               world[i][j] = ' ';
  89.  
  90.           for (i = 1; i < 21; i+=2)
  91.             for (j = 8; j < 75; j += 4)
  92.               world[i][j] = '.';                     /* corners */
  93.  
  94.           for (i = 0; i < 20; i++) {
  95.             world[i][6] = '|';            /* left edge of world */
  96.         world[i][74] = '|';          /* right edge of world */
  97.       }
  98.           for (j = 6; j < 75; j++) {
  99.             world[20][j] = '-';          /* lower edge of world */
  100.         world[0][j] = '-';             /* upper edge of world */
  101.       }
  102.  
  103.           world[1][0] = 'S';            world[22][66] = 'A';
  104.           world[2][0] = 'T';          world[22][67] = 'V';
  105.           world[3][0] = 'R';        world[22][68] = 'E';
  106.           world[4][0] = 'E';        world[22][69] = 'N';
  107.           world[5][0] = 'E';        world[22][70] = 'U';
  108.           world[6][0] = 'T';        world[22][71] = 'E';
  109.           world[7][0] = 'S';        world[22][72] = 'S';
  110.  
  111.           world[1][3] = '1';  world[1][4] = '0';
  112.           for (i = 3, c = '9'; i < 21; i += 2, c--)
  113.             world[i][4] = c;                  /* number streets */
  114.  
  115.           for (j = 8, c = '1'; j < 75; j += 4, c++) {
  116.             world[21][j] = c;                 /* number avenues */
  117.             if (c > '9') {
  118.                 world[21][--j] = '1';
  119.                 world[21][++j] = c - 10;
  120.             }
  121.           }
  122. }
  123.  
  124. readworld(buf)    /* input values from old world file */
  125. FILE *buf;
  126. {
  127.       int i,j;
  128.  
  129.       fscanf(buf,"%d %d %d",&kst,&kav,&bag);
  130.       kdir = getc(buf);
  131.       for (i = 0; i < 23; i++)
  132.         for (j = 0; j < 75; j++)
  133.           world[i][j] = getc(buf);
  134. }
  135.  
  136.  
  137. printworld()    /* output values stored in world array */
  138. {
  139.           int i,j,kst2,kav2;
  140.  
  141.           for (i = 0; i < 23; i++) {
  142.             for (j = 0; j < 75; j++)
  143.               printf("%c",world[i][j]);
  144.             printf("\n");
  145.           }
  146.       set_curs(23,37,0,"");
  147.       kst2 = (21 - kst)/2;
  148.       kav2 = (kav - 4)/4;
  149.       printf("KAREL'S ST= %d  AVE= %d  DIR= %c BAG= %d",
  150.             kst2,kav2,kdir,bag);
  151. }
  152.  
  153.  
  154. kareloc()/* determine street, avenue and direction for KAREL */
  155. {
  156.           char ans,k;
  157.  
  158.       k = world[kst][kav];
  159.       do {
  160.          if (kst != 0 && (k == '^' || k == 'V' || 
  161.                   k == '>' || k == '<')) {
  162.         world[kst][kav] = '.';
  163.             set_curs(kst,kav,1,".");
  164.          }
  165.          do {
  166.         set_curs(23,0,75,"KAREL'S STREET?");
  167.         kst = getint();
  168.          } while (kst == 0 || kst > 10);
  169.          do {
  170.         set_curs(23,0,75,"KAREL'S AVENUE?");
  171.         kav  = getint();
  172.          } while (kav == 0 || kav > 17);
  173.          kst = 21 - 2 * kst;
  174.          kav = 4 + 4 * kav;
  175.          set_curs(23,0,75,"DIRECTION? (N/S/E/W)");
  176.          kdir = toupper(getchr());
  177.          storekarel();
  178.          set_curs(kst,kav,1,"");
  179.          printf("%c",kdir);
  180.          set_curs(23,0,75,"IS KAREL'S LOCATION CORRECT? (Y/N)");
  181.          if ((ans = toupper(getchr())) != 'Y') {
  182.           set_curs(kst,kav,1,"");
  183.         printf("%c", world[kst][kav]);
  184.          }
  185.      } while (ans != 'Y');
  186.      if (world[kst][kav] == '.')
  187.         world[kst][kav] = kdir;
  188. }
  189.  
  190.  
  191. storekarel()   /* determine KAREL's direction from console input */
  192. {        
  193.          char k;
  194.  
  195.          switch(kdir) {
  196.          case 'N':
  197.         kdir = '^';
  198.          break;
  199.          case 'S':
  200.         kdir = 'V';
  201.         break;
  202.          case 'E':
  203.         kdir = '>';
  204.         break;
  205.          case 'W':
  206.              default:
  207.         kdir = '<';
  208.          }  
  209. }
  210.  
  211.  
  212.  
  213. beeploc()  /* determine beeper locations */
  214. {
  215.            int bst,bav,valid;
  216.       char ans;
  217.  
  218.       ans = 'Y';
  219.       while (ans != 'N') {
  220.          do {
  221.         set_curs(23,0,75,"STREET?");
  222.         bst = getint();
  223.          } while (bst == 0 || bst > 10);
  224.          do {
  225.         set_curs(23,0,75,"AVENUE?");
  226.         bav = getint();
  227.          } while (bav == 0 || bav > 17);
  228.          bst = 21 - 2 * bst;
  229.          bav = 4 + 4 * bav;
  230.          set_curs(23,0,75,"TYPE A TO ADD OR D TO DELETE BEEPER");
  231.          if ((ans = toupper(getchr())) != 'D') { 
  232.             valid = putbeeper(bst,bav);
  233.          if (valid) {
  234.                set_curs(bst,bav,1,"");
  235.             printf("%c",world[bst][bav]);
  236.                set_curs(23,0,75,"IS BEEPER LOCATION CORRECT?(Y/N)");
  237.                if ((ans = toupper(getchr())) != 'Y') {
  238.               pickbeeper(bst,bav);
  239.               set_curs(bst,bav,1,"");
  240.               printf("%c",world[bst][bav]);
  241.            }
  242.                 }
  243.          } else {
  244.           pickbeeper(bst,bav);
  245.           set_curs(bst,bav,1,"");
  246.           printf("%c",world[bst][bav]);
  247.            }
  248.         set_curs(23,0,75,"OTHER BEEPER LOCATIONS? (Y/N)");
  249.         ans = toupper(getchr());
  250.      } 
  251.     
  252. }
  253.  
  254.  
  255. bagloc() /* determine number of beepers in beeper bag */
  256. {
  257.       char ans;
  258.  
  259.       do {
  260.          set_curs(23,0,75,"HOW MANY BEEPERS IN BEEPER BAG?");
  261.          bag = getint();
  262.          set_curs(23,0,75,"");
  263.          printf("%d BEEPERS IN BAG, CORRECT? (Y/N)",bag);
  264.       } while ((ans = toupper(getchr())) != 'Y');
  265. }
  266.  
  267.  
  268. putbeeper(bst,bav) /* place one beeper in the world */
  269. int bst,bav;       /* at bst street and bav avenue  */
  270. {
  271.       char k;
  272.  
  273.       k = world[bst][bav];
  274.       if (k == '9') {
  275.          set_curs(23,0,75,"NO MORE THAN 9 BEEPERS ON A CORNER."); 
  276.          set_curs(23,36,0,"TYPE ANY CHARACTER TO CONTINUE");
  277.          getchr();
  278.          return (0);
  279.       } else {
  280.            if (k == '.' || k == '^' || k == 'V' ||
  281.                        k == '>' || k == '<')
  282.               k = '@';
  283.            else if (k == '@')
  284.                k = '2';
  285.            else ++k;
  286.            world[bst][bav] = k;
  287.            return(1);
  288.         }
  289. }
  290.  
  291.  
  292. pickbeeper(bst,bav)  /* remove one beeper from the world   */
  293. int bst,bav;         /* location bst street and bav avenue */
  294. {
  295.       char k;
  296.       
  297.       k = world[bst][bav];
  298.       if (k == '.' || k == '^' || k == 'V' ||
  299.                       k == '<' || k == '>') {
  300.          set_curs(23,0,75,"NO BEEPER ON CORNER.");
  301.          set_curs(23,21,0,"TYPE ANY CHARACTER TO CONTINUE.");
  302.          getchr();
  303.       } else {
  304.            if (bst == kst && bav == kav && k == '@')
  305.           k = kdir;
  306.             else if (k == '2')
  307.                 k = '@';
  308.            else if (k != '@')
  309.                --k;
  310.            else k = '.';
  311.            world[bst][bav] = k;
  312.         }
  313. }
  314.  
  315.  
  316. wallsloc()   /* determine wall location(s) */
  317. {
  318.       int i,j,s1,s2,st1,st2,a1,a2,av1,av2,horiz;
  319.       char ans;
  320.  
  321.       do {
  322.          do {
  323.             set_curs(23,0,75,"BETWEEN WHAT STREETS?");
  324.         s1 = getint();
  325.         set_curs(23,0,40,"?");
  326.         s2 = getint();
  327.          } while (s1 < 0 || s2 < 0 || s1 > 11 || s2 > 11);
  328.          st1 = min(s1,s2);
  329.          st2 = max(s1,s2);
  330.          horiz = abs(st2 - st1);
  331.          st1 = 20 - 2 * st1;
  332.          st2 = 22 - 2 * st2;
  333.          do {
  334.         set_curs(23,0,40,"BETWEEN WHAT AVENUES?");
  335.         a1 = getint();
  336.         set_curs(23,0,40,"?");
  337.         a2 = getint();
  338.          } while (a1 < 0 || a2 < 0 || a1 > 18 || a2 > 18);
  339.          av1 = min(a1,a2);
  340.          av2 = max(a1,a2);
  341.          av1 = 6 + 4 * av1;
  342.          av2 = 2 + 4 * av2;
  343.          set_curs(23,0,75,"TYPE A TO ADD OR D TO DELETE THE WALL.");
  344.          if ((ans = toupper(getchr())) != 'D') {
  345.             addwall(st1,st2,av1,av2,horiz);
  346.             set_curs(23,0,40,"IS WALL LOCATION CORRECT? (Y/N)");
  347.             if ((ans = toupper(getchr())) != 'Y')
  348.            erasewall(st1,st2,av1,av2,horiz);
  349.             else {
  350.            set_curs(23,0,40,"IS THIS THE LAST WALL? (Y/N)");
  351.            ans = toupper(getchr());
  352.             }
  353.           } else {
  354.            erasewall(st1,st2,av1,av2,horiz);
  355.            set_curs(23,0,40,"IS THIS THE LAST WALL? (Y/N)");
  356.            ans = toupper(getchr());
  357.         }
  358.       } while (ans != 'Y');
  359. }
  360.  
  361.  
  362. addwall(st1,st2,av1,av2,horiz)   /* add one wall to the world */
  363. int st1,st2,av1,av2,horiz;
  364. {
  365.            int i,j;
  366.  
  367.        if (horiz == 1) 
  368.           for (j = av1; j <= av2; j++) {
  369.               if (world[st1][j] == '|' ||
  370.               world[st1][j] == '+')
  371.               world[st1][j] = '+';
  372.               else world[st1][j] = '-';      
  373.                   set_curs(st1,j,1,"");
  374.           printf("%c",world[st1][j]);
  375.           }
  376.         else for (i = st2; i <= st1; i++) {
  377.              if (world[i][av1] == '-' ||
  378.                  world[i][av1] == '+')
  379.                  world[i][av1] = '+';
  380.                  else world[i][av1] = '|'; 
  381.               set_curs(i,av1,1,"");
  382.              printf("%c",world[i][av1]);
  383.          }
  384. }
  385.  
  386.  
  387. erasewall(st1,st2,av1,av2,horiz)  /* remove one wall from the world */
  388. int st1,st2,av1,av2,horiz;
  389.        int i,j;
  390.  
  391.        if (horiz == 1)
  392.           for (j = av1; j <= av2; j++) {
  393.         if (j == 6 || j ==74)
  394.            world[st1][j] = '|';
  395.         else if (world[st1][j] == '+')
  396.             world[st1][j] = '|';
  397.         else world[st1][j] = ' ';
  398.         set_curs(st1,j,1,"");
  399.         printf("%c",world[st1][j]);
  400.           }
  401.            else for (i = st2; i <= st1; i++) {
  402.           if (i == 0 || i == 20)
  403.              world[i][av1] = '-';
  404.           else if (world[i][av1] == '+')
  405.               world[i][av1] = '-';
  406.           else world[i][av1] = ' ';
  407.           set_curs(i,av1,1,"");
  408.           printf("%c",world[i][av1]);
  409.         }
  410. }
  411.  
  412.  
  413.  
  414. getint()  /* determine integer input from console */
  415. {
  416.       char str[5];
  417.       int in;
  418.  
  419.       inputs(str);
  420.       in = atoi(str);
  421.       return in;
  422. }
  423.  
  424.  
  425. inputs(str)   /* read string input from console */
  426. char str[];
  427. {
  428.       int j;
  429.  
  430.       j = 0;
  431.       while ((str[j++] = getchr()) != '\r')
  432.           ;
  433.       str[--j] = '\0';
  434. }
  435.  
  436.  
  437. alterations()   /* additional changes to the world */
  438.       char ans;
  439.  
  440.       set_curs(23,0,40,"ANY FURTHER CHANGES TO THE WORLD? (Y/N)");
  441.       while ((ans = toupper(getchr())) != 'N') {
  442.          set_curs(23,0,40,"CHANGE KAREL'S POSITION? (Y/N)");
  443.          if ((ans = toupper(getchr())) == 'Y')
  444.         kareloc();
  445.          set_curs(23,0,40,"CHANGE BEEPERS IN WORLD? (Y/N)");
  446.          if ((ans = toupper(getchr())) == 'Y')
  447.         beeploc();
  448.          set_curs(23,0,40,"CHANGE BEEPERS IN BAG? (Y/N)");
  449.          if ((ans = toupper(getchr())) == 'Y')
  450.         bagloc();
  451.          set_curs(23,0,40,"CHANGE WALL LOCATIONS? (Y/N)");
  452.          if ((ans = toupper(getchr())) == 'Y')
  453.         wallsloc();
  454.          set_curs(23,0,40,"ANY FURTHER CHANGES TO THE WORLD? (Y/N)");
  455.       }
  456. }
  457.  
  458.  
  459. set_curs(row,col,blanks,mess) /* set cursor and print message */
  460. int row,col,blanks;
  461. char *mess;
  462. {
  463.         int j;
  464.  
  465.       printf("%s%c%c", CURPOS, row + X_POS, col + Y_POS);
  466.       for (j = 1; j <= blanks; j++)
  467.         printf(" ");    /* blank out previous message */
  468.       printf("%s%c%c", CURPOS, row + X_POS, col + Y_POS);
  469.       printf("%s", mess);   /* output current message */
  470. }
  471.  
  472.  
  473.  
  474. saveworld(argv,buf)   /* save world array in second file */
  475. char **argv;
  476. FILE *buf;
  477. {
  478.       int i,j;
  479.  
  480.       fcreat(argv[2],buf);
  481.       fprintf(buf,"%d %d %d\n",kst,kav,bag);
  482.       putc(kdir,buf);
  483.       for (i = 0; i < 23; i++)
  484.         for (j = 0; j < 75; j++) 
  485.           putc(world[i][j],buf);
  486.       putc(CPMEOF,buf);
  487.       fclose(buf);
  488. }
  489.  
  490.  
  491. getchr()  /* low-level character input */
  492. {
  493.       char c;
  494.  
  495.       c = bios(3);
  496.       putchr(c);
  497.       return c;
  498. }
  499.  
  500.  
  501. putchr(c)   /* low-level character output */
  502. char c;
  503. {
  504.       bios(4,c);
  505. }
  506.  
  507.  
  508.  
  509. createpgm(argv)   /* create C pgm from parse tree */
  510. char **argv;
  511. {
  512.       int i,in,d,reloc[10];
  513.       char newname[10][MAXLINE],fname[12];
  514.       char *test[19],*j[9];
  515.       char ibuf[BUFSIZ],obuf[BUFSIZ];
  516.       
  517.       last = 0;
  518.       init(test); 
  519.       if (fopen(argv[1],ibuf) == ERROR)
  520.          printf("CAN'T FIND TREE FILE.\n");
  521.           else {
  522.          strcpy(fname,argv[1]); 
  523.          strcat(fname,".C");
  524.          if (fcreat(fname,obuf) == ERROR) 
  525.         printf("CAN'T CREATE NEW FILE.\n");
  526.          else {
  527.         fprintf(obuf,"#include <karel.h>\n");
  528.         setupspace(j);
  529.         fprintf(obuf,"int j1,j2,j3,j4,j5,j6,j7,j8;\n");
  530.             fscanf(ibuf,"%d",&i);   
  531.             fscanf(ibuf,"%d %d %d",&i,&in,&d);
  532.             while (i != 9) { /* translate to end of program */
  533.                 createline(j,i,in,d,newname,reloc,test,ibuf,obuf);
  534.                 fscanf(ibuf,"%d %d %d",&i,&in,&d);
  535.              }
  536.              fprintf(obuf,"  turnoff(4);\n");
  537.              fprintf(obuf,"  } \n");
  538.              putc(CPMEOF,obuf);
  539.              fclose(ibuf);
  540.              fclose(obuf);
  541.           } 
  542.       } 
  543. }
  544.  
  545. setupspace(j)      /*  initialize array of ITERATE loop counters */
  546. char *j[9];
  547. {
  548.  
  549.      char *alloc();
  550.      int i;
  551.  
  552.        for (i = 0; i <= 8; i++)
  553.           j[i] = alloc(2);
  554.      j[1] = "j1";        j[2] = "j2";
  555.      j[3] = "j3";        j[4] = "j4";
  556.      j[5] = "j5";        j[6] = "j6";
  557.      j[7] = "j7";        j[8] = "j8";
  558. }
  559.  
  560.  
  561. init(test)         /* initialize array with C version of tests */
  562. char *test[19];
  563. {
  564.  
  565.       int i;
  566.       char *alloc();
  567.  
  568. for (i = 0; i < 19; i++)    /* allocate space for tests */
  569.   test[i] = alloc(10);
  570.  
  571. test[0] = "nnorth";
  572. test[1] = "!nnorth";
  573. test[2] = "ssouth";
  574. test[3] = "!ssouth";
  575. test[4] = "eeast";
  576. test[5] = "!eeast";
  577. test[6] = "wwest";
  578. test[7] = "!wwest";
  579. test[8] = "ccorner";
  580. test[9] = "!ccorner";
  581. test[10] = "bbag";
  582. test[11] = "!bbag";
  583. test[12] = "ffront";
  584. test[13] = "!ffront";
  585. test[14] = "lleft";
  586. test[15] = "!lleft";
  587. test[16] = "rright";
  588. test[17] = "!rright";
  589. }
  590.  
  591.  
  592. createline(j,i,in,d,newname,reloc,test,ibuf,obuf)
  593. int i,in,d,reloc[10];
  594. char newname[10][MAXLINE],*test[19],*j[9];
  595. FILE *ibuf,*obuf;
  596. {
  597.       int k;
  598.       char w[MAXLINE];
  599.  
  600.       for (k = 0; k < (in - 1); k++)
  601.         fprintf(obuf,"  ");
  602.       if (d != 4)
  603.          switch(i) {
  604.          case 0:
  605.         fprintf(obuf,"move();\n");
  606.         break;
  607.          case 1:
  608.         fprintf(obuf,"turnleft();\n");
  609.         break;
  610.          case 2:
  611.         fprintf(obuf,"pickbeeper();\n");
  612.             break;
  613.          case 3:
  614.         fprintf(obuf,"putbeeper();\n");
  615.         break;
  616.          case 4:
  617.         fprintf(obuf,"turnoff(0);\n");
  618.         break;
  619.          case 5:
  620.         fprintf(obuf,"{ \n");
  621.         break;
  622.          case 7:
  623.         fprintf(obuf,"\nmain(argc,argv) \n");
  624.           fprintf(obuf,"int argc;\n");
  625.         fprintf(obuf,"char **argv;\n");
  626.               fprintf(obuf,"  { \n");
  627.         fprintf(obuf,"  set_up(argv);\n");
  628.         break;
  629.          case 8:
  630.         fprintf(obuf,"} \n");
  631.         break;
  632.          case 11:
  633.         fscanf(ibuf,"%d",&i);   /* read test */ 
  634.         fprintf(obuf,"if (%s)\n",test[i]);
  635.         fscanf(ibuf,"%d",&i);   /* skip THEN */
  636.         break;
  637.          case 13:
  638.         fprintf(obuf,"else\n");
  639.         break;
  640.          case 14:
  641.         fscanf(ibuf,"%d",&i);
  642.         fprintf(obuf,"for (%s = 0; %s < %d; %s++)\n",
  643.             j[in],j[in],i,j[in]);
  644.         break;
  645.          case 15:
  646.         fscanf(ibuf,"%d",&i);
  647.         fprintf(obuf,"while (%s)\n",test[i]);
  648.         break;
  649.          case 16:
  650.         fscanf(ibuf,"%d",&i);
  651.         i = reloc[i] = last++;
  652.         k = 0;
  653.         while ((w[k++] = getc(ibuf)) != '\n')
  654.             if (w[k - 1] == '-')
  655.                w[k - 1] = '_';
  656.         k -= 3;
  657.         w[k] = '\0';
  658.         strcpy(newname[i],w); 
  659.         fprintf(obuf,"\n%s()\n",newname[i]);
  660.         break;
  661.          default:
  662.         ;
  663.          }
  664.       else { 
  665.          i = reloc[i];
  666.          fprintf(obuf,"%s();\n",newname[i]);
  667.       }
  668. }
  669.